//
// Decompiled with: Decompiler.NET, Version=1.3.1.18439, Culture=neutral, PublicKeyToken=null, Version: 1.3.1.18439
// Decompilation Started at: 3/15/2009 10:34:26 PM
// Copyright 2003 - 2004, Jungle Creatures, Inc., All Rights Reserved. 
// Written by Jonathan Pierce, Email: support@junglecreatures.com
//

namespace PatientManagement

{
		
		#region Namespace Import Declarations
		
			using System.Collections.Specialized;
			using System.ComponentModel;
			using System.Configuration;
			using System.Data.Common;
			using System.Data;
			using System.Data.SqlClient;
			using System.Drawing;
			using System;
			using System.IO;
			using System.Threading;
			using System.Windows.Forms;
			
		#endregion
		
	public class frmRestore : Form
	
	{
		
		#region Fields
			private Button cmdCancel;
			private Button cmdCloseConnection;
			private Button cmdOpenFile;
			private Button cmdRestore;
			private Container components;
			private string connStr;
			private string connStrMaster;
			private Label label1;
			private SplashScreen sp;
			private Thread th1;
			private TextBox txtFilePath;
		#endregion
		
		#region Constructors
		
			public frmRestore ()
			
			{
				this.components = ((System.ComponentModel.Container) null);
				this.InitializeComponent ();
				this.connStrMaster = ConfigurationSettings.AppSettings["SqlCnnStringMaster"];
				this.connStr = ConfigurationSettings.AppSettings["SqlCnnString"];
				return;
			}
			
		#endregion
		
		#region Methods
		
			private void cmdCancel_Click (object sender, EventArgs e)
			
			{
				base.Close ();
				return;
			}
			
			private void cmdCloseConnection_Click (object sender, EventArgs e)
			
			{
				SqlConnection theSqlConnection;
				SqlCommand theSqlCommand;
				SqlDataAdapter theSqlDataAdapter;
				DataSet theDataSet;
				int i;
				SqlCommand theSqlCommand2;
				this.Cursor = Cursors.WaitCursor;
				theSqlConnection = new SqlConnection (this.connStrMaster);
				theSqlCommand = new SqlCommand ("USE master EXEC sp_who \'clinical\'", theSqlConnection);
				theSqlConnection.Open ();
				theSqlDataAdapter = new SqlDataAdapter (theSqlCommand);
				theDataSet = new DataSet ();
				int i2 = theSqlDataAdapter.Fill (theDataSet, "Process");
				i = 0;
				goto L_008F;
				
			L_0048:
				
				{
				}
				theSqlCommand2 = new SqlCommand (string.Concat ("Kill ", theDataSet.Tables[0].Rows[i]["spid"].ToString ()), theSqlConnection);
				int i3 = theSqlCommand2.ExecuteNonQuery ();
				i++;
				
			L_008F:
				
				{
				}
				if (i < theDataSet.Tables[0].Rows.Count)
				{
					goto L_0048;
				}
				theSqlConnection.Close ();
				DialogResult theDialogResult = MessageBox.Show ("T?t c? c?c k?t n?i ??u ???c ??ng.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				this.cmdRestore.Enabled = true;
				this.Cursor = Cursors.Arrow;
				return;
			}
			
			private void cmdOpenFile_Click (object sender, EventArgs e)
			
			{
				OpenFileDialog theOpenFileDialog;
				theOpenFileDialog = new OpenFileDialog ();
				theOpenFileDialog.FilterIndex = 1;
				theOpenFileDialog.RestoreDirectory = true;
				if (theOpenFileDialog.ShowDialog () != DialogResult.OK)
				{
					goto L_002E;
				}
				this.txtFilePath.Text = theOpenFileDialog.FileName;
				
			L_002E:
				return;
			}
			
			private void cmdRestore_Click (object sender, EventArgs e)
			
			{
				SqlConnection theSqlConnection;
				SqlCommand theSqlCommand;
				if (File.Exists (this.txtFilePath.Text))
				{
					goto L_002A;
				}
				DialogResult theDialogResult = MessageBox.Show ("Xin vui l?ng ch?n file kh?i ph?c", "Restore", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
				goto L_013A;
				
			L_002A:
				
				{
				}
				base.ParentForm.Cursor = Cursors.AppStarting;
				this.th1 = new Thread (new ThreadStart (this.Thread1));
				this.th1.Start ();
				this.Cursor = Cursors.WaitCursor;
				theSqlConnection = new SqlConnection (this.connStrMaster);
				theSqlConnection.Open ();
				
			L_0079:
				try
				{
					theSqlCommand = new SqlCommand (string.Concat ("RESTORE DATABASE LeHanhSystemVN  FROM DISK =\'", this.txtFilePath.Text, "\'"), theSqlConnection);
					int i = theSqlCommand.ExecuteNonQuery ();
					this.sp.EndDisplay ();
					this.th1 = ((Thread) null);
					DialogResult theDialogResult2 = MessageBox.Show ("Restore successful", "Restore", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					DialogResult theDialogResult3 = MessageBox.Show ("?ng d?ng s? ???c ??ng. Xin vui l?ng m? l?i", "Close", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					this.Cursor = Cursors.Arrow;
					base.Close ();
					Application.Exit ();
				}
				catch
				{
					
				L_00F1:
					
					{
					}
					this.sp.EndDisplay ();
					this.th1 = ((Thread) null);
					DialogResult theDialogResult4 = MessageBox.Show ("Vi?c kh?i ph?c d? li?u b? l?i. Xin vui l?ng l?m l?i", "Restore", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
					this.Cursor = Cursors.Arrow;
				}
				
			L_0124:
				
				{
				}
				theSqlConnection.Close ();
				base.ParentForm.Cursor = Cursors.Arrow;
				
			L_013A:
				return;
			}
			
			protected override void Dispose (bool disposing)
			
			{
				if (! disposing)
				{
					goto L_0016;
				}
				if (this.components == null)
				{
					goto L_0016;
				}
				this.components.Dispose ();
				
			L_0016:
				
				{
				}
				base.Dispose (disposing);
				return;
			}
			
			private void frmRestore_Load (object sender, EventArgs e)
			
			{
				this.cmdRestore.Enabled = false;
				return;
			}
			
			private void InitializeComponent ()
			
			{
				Control[] theControlArray;
				this.cmdOpenFile = new Button ();
				this.txtFilePath = new TextBox ();
				this.label1 = new Label ();
				this.cmdRestore = new Button ();
				this.cmdCancel = new Button ();
				this.cmdCloseConnection = new Button ();
				base.SuspendLayout ();
				this.cmdOpenFile.Location = new Point (344, 16);
				this.cmdOpenFile.Name = "cmdOpenFile";
				this.cmdOpenFile.Size = new System.Drawing.Size (32, 23);
				this.cmdOpenFile.TabIndex = 12;
				this.cmdOpenFile.Text = "...";
				this.cmdOpenFile.Click += new EventHandler (this.cmdOpenFile_Click);
				this.txtFilePath.Location = new Point (64, 16);
				this.txtFilePath.Name = "txtFilePath";
				this.txtFilePath.Size = new System.Drawing.Size (272, 20);
				this.txtFilePath.TabIndex = 11;
				this.txtFilePath.Text = "";
				this.label1.AutoSize = true;
				this.label1.Location = new Point (8, 16);
				this.label1.Name = "label1";
				this.label1.Size = new System.Drawing.Size (52, 13);
				this.label1.TabIndex = 13;
				this.label1.Text = "Ch?n file:";
				this.cmdRestore.Location = new Point (152, 48);
				this.cmdRestore.Name = "cmdRestore";
				this.cmdRestore.Size = new System.Drawing.Size (100, 23);
				this.cmdRestore.TabIndex = 14;
				this.cmdRestore.Text = "Kh?i ph?c d? li?u";
				this.cmdRestore.Click += new EventHandler (this.cmdRestore_Click);
				this.cmdCancel.Location = new Point (264, 48);
				this.cmdCancel.Name = "cmdCancel";
				this.cmdCancel.Size = new System.Drawing.Size (56, 23);
				this.cmdCancel.TabIndex = 15;
				this.cmdCancel.Text = "Cancel";
				this.cmdCancel.Click += new EventHandler (this.cmdCancel_Click);
				this.cmdCloseConnection.Location = new Point (72, 48);
				this.cmdCloseConnection.Name = "cmdCloseConnection";
				this.cmdCloseConnection.Size = new System.Drawing.Size (72, 23);
				this.cmdCloseConnection.TabIndex = 16;
				this.cmdCloseConnection.Text = "Ng?t k?t n?i";
				this.cmdCloseConnection.Click += new EventHandler (this.cmdCloseConnection_Click);
				this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
				base.ClientSize = new System.Drawing.Size (384, 85);
				theControlArray = new Control[6];
				theControlArray[0] = ((Control) this.cmdCloseConnection);
				theControlArray[1] = ((Control) this.cmdCancel);
				theControlArray[2] = ((Control) this.cmdRestore);
				theControlArray[3] = ((Control) this.label1);
				theControlArray[4] = ((Control) this.cmdOpenFile);
				theControlArray[5] = ((Control) this.txtFilePath);
				base.Controls.AddRange (theControlArray);
				base.MaximizeBox = false;
				base.MinimizeBox = false;
				base.Name = "frmRestore";
				this.Text = "Restore";
				base.Load += new EventHandler (this.frmRestore_Load);
				base.ResumeLayout (false);
				return;
			}
			
			private void Thread1 ()
			
			{
				this.sp = new SplashScreen ();
				this.sp.Show ();
				this.sp.BeginDisplay ();
				return;
			}
			
		#endregion
	}
	
}

